﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QL_Nha_Sach_Phuong_Nam
{
    public partial class FormThongKeSach : Form
    {
        CXuLySachKho XulySach_Kho;

        public FormThongKeSach()
        {
            InitializeComponent();
        }

        #region Load dữ liệu lên Form

        private void FormQuanLySachTrenKe_Load(object sender, EventArgs e)
        {
            XulySach_Kho = new CXuLySachKho();

            HienThiSachKe(XulySach_Kho.getdsSachTrungBay());
            HienThiSachKho(XulySach_Kho.getdsSachKho());
        }

        #endregion

        private void HienThiSachKho(List<TonKho> kho)
        {
            lvSach_Kho.Items.Clear();
            foreach (TonKho tk in kho)
            {
                ListViewItem lvi = lvSach_Kho.Items.Add(tk.Sach.SachNo);
                lvi.SubItems.Add(tk.Sach.SachName);
                lvi.SubItems.Add(tk.Sach.NhaXuatBan.NhaXuatBanName);
                lvi.SubItems.Add(tk.Sach.NhaXuatBan.ToString());
                lvi.SubItems.Add(hienthiSachTacGia(tk.Sach));
                lvi.SubItems.Add(hienthiSachTheLoai(tk.Sach));
                lvi.SubItems.Add(tk.SoLuong.ToString());
            }
        }

        private void HienThiSachKe(List<TonKho> ke)
        {
            lvSach_Ke.Items.Clear();
            foreach(TonKho tk in ke)
            {
                ListViewItem lvi = lvSach_Ke.Items.Add(tk.Sach.SachNo);
                lvi.SubItems.Add(tk.Sach.SachName);
                lvi.SubItems.Add(tk.Sach.NhaXuatBan.NhaXuatBanName);
                lvi.SubItems.Add(tk.Sach.NhaXuatBan.ToString());
                lvi.SubItems.Add(hienthiSachTacGia(tk.Sach));
                lvi.SubItems.Add(hienthiSachTheLoai(tk.Sach));
                lvi.SubItems.Add(tk.SoLuong.ToString());
            }
        }

        private string hienthiSachTacGia(Sach sach)
        {
            string s = "";
            foreach (Sach_TacGia stg in sach.Sach_TacGias)
            {
                s += stg.TacGia.TacGiaName + " ";
            }
            return s;
        }
        private string hienthiSachTheLoai(Sach sach)
        {
            string s = "";
            foreach (Sach_TheLoai stl in sach.Sach_TheLoais)
            {
                s += stl.TheLoai.TheLoaiName + " ";
            }
            return s;
        }
    }
}
